<?php

class PublicAction extends BaseAction
{
    protected $UserConfig;

    public function _initialize()
    {
        parent::_initialize();


        if ( ! F($this->UserConfig)) {
            $list = M('UserConfig')->select();

            $this->UserConfig = array();

            foreach ($list as $key=>$r) {
                $this->UserConfig[$r['varname']]=$r['value'];
            }

            F('UserConfig',$this->UserConfig);
        } else {
            $this->UserConfig = F($this->UserConfig);
        }

        //301跳转
        $siteDomains = C('SITE_DOMAINS');
        if (!empty($siteDomains)) {
            $siteDomainArr = explode("\n", C('SITE_DOMAINS'));

            if (in_array($_SERVER['SERVER_NAME'], $siteDomainArr)) {
                header("HTTP/1.1 301 Moved Permanently");
                header("location: http://" . C('SITE_DOMAIN'));
            }
        }

        //获取碎片
        $data_block = M('Block')->where('`groupid`=1 and `lang`=' . LANG_ID)->select();
        if (!empty($data_block)) {
            $block = array();
            foreach ($data_block as $val) {
                $block[$val['id']] = $val['content'];
            }

            $this->assign('block', $block);
        }
    }

    //检测是否登录
    function checkLogin()
    {
        if (empty($_SESSION['user']['username'])) {
            $this->redirect('/login');
        }
    }
}